package com.rbac.web.config;

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;

/**
 * @author gengaoliu
 */
@EnableScheduling
@EnableAsync
@Configuration
public class ScheduleConfig implements SchedulingConfigurer {

  @Bean
  public Executor taskExecutor() {
    // 指定定时任务的线程数量，可根据需求进行自我调节
    return Executors.newScheduledThreadPool(3);
  }

  @Override
  public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
    taskRegistrar.setScheduler(taskExecutor());
  }
}
